const areaNames = `anchor.png, dungeon-gate.png, evil-tower.png, exit-door.png, guarded-tower.png, guards.png, heart-tower.png, magic-portal.png, maze.png, pagoda.png, raise-zombie.png, sword-in-stone.png, sword-smithing.png, tower-fall.png, tree-door.png, uncertainty.png, vertical-banner.png, volcano.png, white-tower.png, wind-hole.png, witch-flight`.replace(/, ?/g, "").split('.png');
// 守卫 按照势力善恶提供 buff 和 debuff
// 不同守卫 提供不同属性的状态
// 21种地点
const areaTips = [
    ["港口", "你可以在港口购买物品或低阶宠物"],
    ["地牢", "是否进入地牢？"],
    ["邪眼守卫", "战斗？交谈？无视？"],
    ["出口", "这是一处地牢或迷宫的出口"],
    ["人类守卫", "战斗？交谈？无视？"],
    ["士兵守卫", "战斗？交谈？无视？"],
    ["治疗守卫", "战斗？交谈？无视？"],
    ["传送门", "你可以传送到当前一层的随机位置"],
    ["迷宫挑战", "是否进入迷宫？"],
    ["塔庙", "祈祷？破坏？无视？"],
    ["亡者归来", "失去少量生命，可以复活最近死去的一只宠物"],
    ["石中剑", "你拔出了石中剑，获得物品，概率获得debuff"],
    ["铁匠", "可以强化物品"],
    ["破碎守卫", "战斗？交谈？无视？"],
    ["森林之门", "是否进入森林？"],
    ["未知", "一处未知之地"],
    ["人类营地", "锻炼？+随机属性休息？恢复生命"],
    ["火山喷发", "躲避？-少量生命；停留？-生命概率获得物品"],
    ["城墙", "修整？+生命+防御-速度；破坏？+攻击-幸运"],
    ["台风眼", "停留？+命中-生命；躲避？+暴击-闪避"],
    ["女巫之夜", "停留？+法力；躲避？获得物品"],
]
const clearAreaScreen = () => {
    let _t = document.querySelector('.areaScreen');
    _t.innerText = '';
    _t.style.display = 'none';
}
const getRandomItem = () => {
    return getRandomRange(0, itemData.length - 1)
}
const getRandomPet = () => {
    return monsterLevel[0][getRandomRange(0, monsterLevel[0].length - 1)]
}
function heroTrain() {
    // 锻炼
    for (let i = 2; i < 4; i++) {
        game.hero.heroInfo.abilities[i] += game.cur_map_floor * 2 + 2;
    }
    renderHeroStat();
}
function heroPray() {
    // 祈祷
    for (let i = 4; i < 6; i++) {
        game.hero.heroInfo.abilities[i] += game.cur_map_floor * 2 + 2;
    }
    renderHeroStat();
}
function heroRest() {
    // 休息
    game.hero.heroInfo.hp += game.cur_map_floor * 10;
    if (game.hero.heroInfo.hp > game.hero.heroInfo.abilities[0]) {
        game.hero.heroInfo.hp = game.hero.heroInfo.abilities[0]
    }
    game.hero.heroInfo.mp += game.cur_map_floor * 5;
    if (game.hero.heroInfo.mp > game.hero.heroInfo.abilities[1]) {
        game.hero.heroInfo.mp = game.hero.heroInfo.abilities[1]
    }
    renderHeroBar();
}
function heroTransport() {
    console.log("踏入传送门");
    game.enterNewArea(getRandomRange(0, 35));
}
function heroStay(aid) {
    game.hero.heroInfo.hp = Math.round(game.hero.heroInfo.hp * 0.7)
    renderHeroBar();
}
function heroStayAway(aid) {
    game.hero.heroInfo.hp = Math.round(game.hero.heroInfo.hp * 0.8)
    renderHeroBar();
}
const meetGuard = (eid) => {
    // 渲染 3 种选项 战斗 交谈 无视
    console.log("遇见守卫", areaTips[eid][0]);
    let btns = []
    btns.push(
        {
            name: "战斗",
            id: getRandomPet(),
            type: "button"
        },
        {
            name: "交谈",
            type: "button"
        },
        {
            name: "无视",
            type: 'button'
        }
    )
    return btns
}
const nearNewMap = (eid) => {
    // new map 渲染 2 进入 离开
    let btns = []
    btns.push(
        {
            name: "进入",
            id: areaTips[eid][0],
            type: "button"
        },
        {
            name: "离开",
            type: "button"
        }
    )
    return btns
}
function talkToGuard(mid) {
    // 触发战斗概率 获得随机宝物概率 获得随机后6项属性概率 获得经验值概率
    let rate = [80, 60, 40, 20];
    let p = getRandomRange(1, 100);
    if (p > rate[0]) {
        battleHandler(getRandomPet())
    } else if (p > rate[1]) {
        game.hero.getItem(getRandomItem());
    } else if (p > rate[2]) {
        game.hero.heroInfo.abilities[getRandomRange(2, 4)] += getRandomRange(1, 5);
        game.hero.heroInfo.abilities[getRandomRange(5, 7)] += getRandomRange(1, 5);
        renderHeroStat();
    } else if (p > rate[3]) {
        game.hero.getExp(getRandomRange(20, 80));
        renderHeroStat();
    }
}
// 特殊效果 func 弹出对话框 选择获得加成还是其他--加入事件队列
// 进入小地图 newmap
const areaData = [
    {
        func: () => {
            // 渲染 3 物品 3 宠物 花费经验购买 点击图标购买 渲染“离开”按钮 7
            let btns = []
            for (let i = 0; i < 3; i++) {
                // 类型 id 花费属性 花费数值
                let item = {
                    id: ['item', getRandomItem(), 'exp', 50],
                    type: 'div'
                }
                btns.push(item)
            }
            for (let j = 0; j < 3; j++) {
                let pet = {
                    id: ['monster', getRandomPet(), 'exp', 50],
                    type: 'div'
                }
                btns.push(pet)
            }
            btns.push({
                name: "离开",
                type: "button"
            })
            return btns
        }
    },
    {
        func: nearNewMap
    },
    {
        func: meetGuard
    },
    {
        func: () => {
            // 离开当前小地图
            console.log("离开小地图");
        }
    },
    {
        func: meetGuard
    },
    {
        func: meetGuard
    },
    {
        func: meetGuard
    },
    {
        func: () => {
            // 渲染 2 传送 离开
            let btns = []
            btns.push(
                {
                    name: "传送",
                    type: "button"
                },
                {
                    name: "离开",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: nearNewMap
    },
    {
        func: () => {
            // 渲染 3 种选项 祈祷 破坏 无视
            let btns = []
            btns.push(
                {
                    name: "祈祷",
                    type: "button"
                },
                {
                    name: "破坏",
                    type: "button"
                },
                {
                    name: "无视",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            // 2 种 复活 离开
            let btns = []
            btns.push(
                {
                    name: "复活",
                    type: "button"
                },
                {
                    name: "离开",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            // 2 种 拔出 离开
            let btns = []
            btns.push(
                {
                    name: "拔出",
                    type: "button"
                },
                {
                    name: "离开",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            // 2 种 强化 离开
            let btns = []
            btns.push(
                {
                    name: "强化",
                    type: "button"
                },
                {
                    name: "离开",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: meetGuard
    },
    {
        func: nearNewMap
    },
    {
        func: () => {
            // 未知之地（非地牢出入口、门和守卫） 2 种 进入 离开
            let btns = []
            btns.push(
                {
                    name: "探索",
                    type: "button"
                },
                {
                    name: "离开",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            // 2 种 锻炼 休息
            let btns = []
            btns.push(
                {
                    name: "锻炼",
                    type: "button"
                },
                {
                    name: "休息",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            // 2 种 躲避 停留
            let btns = []
            btns.push(
                {
                    name: "躲避",
                    type: "button"
                },
                {
                    name: "停留",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            // 2 种 修整 破坏
            let btns = []
            btns.push(
                {
                    name: "修整",
                    type: "button"
                },
                {
                    name: "破坏",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            let btns = []
            btns.push(
                {
                    name: "停留",
                    type: "button"
                },
                {
                    name: "躲避",
                    type: "button"
                }
            )
            return btns
        }
    },
    {
        func: () => {
            let btns = []
            btns.push(
                {
                    name: "停留",
                    type: "button"
                },
                {
                    name: "躲避",
                    type: "button"
                }
            )
            return btns
        }
    },
]
